package usaco.c2010.march.bronze;
import java.util.Scanner;

/*
 * p3601
 * USACO 2010 March
 */

public class p3601 {
	
	static int L1, L2;
	static int[] S1, S2;
	static int[][] m;

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		L1 = scanner.nextInt();
		L2 = scanner.nextInt();
		S1 = new int[L1+1];
		S2 = new int[L2+1];
		m = new int[L1+1][L2+1];
		for (int i=1;i<=L1;++i) {
			S1[i] = scanner.nextInt();
		}
		for (int i=1;i<=L2;++i) {
			S2[i] = scanner.nextInt();
		}
		int max = 0;

		for (int i=1;i<=L1;++i) {
			for (int j=1;j<=L2;++j) {
				if (S1[i] == S2[j]) {
					m[i][j] = m[i-1][j-1] + 1;
					if (m[i][j] > max) {
						max = m[i][j];
					}
				}
			}
		}
		
		System.out.println(max);
	}

}
